<%--
 *  File:    CategoryEdit.jsp
 *  @Author: Langerwang 
 *  Date:    2001/12/14
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  //init param
  Category cat = Category.getInstance("jsp.CategoryEdit");  
  String privilegeCode = "10201,L201";
  String strModuleName = "PCM";
  String contextPath = request.getContextPath();
%>



<%
  //get curuserinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  String strCurOrgName = (String)CurUserInfo.get("orgname");
  Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  if(nCurOrgId == null)
  {
    nCurOrgId = new Integer(-1234567);
  } 

  //get category info
  String strCategoryId = (String)request.getParameter("categoryid");
  String strParentCategoryId = (String)request.getParameter("parentcategoryid"); 
  String strReadOnly = "";  
  boolean bIsEdit = false;
  if(strCategoryId != null)
  {
    bIsEdit = true;
    strReadOnly = "readonly";;
  }


  boolean bIsNewChild = !bIsEdit;
%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
 

<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="categoryedit"/>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/InitEdit.inc" %>
<%
  HashMap categoryInfo = (HashMap)pageContext.getAttribute("categoryinfo");  
  if(categoryInfo == null)
  {
    categoryInfo = new HashMap();
  }   
  HashMap parentCategoryInfo = (HashMap)pageContext.getAttribute("parentcategoryinfo");  
  if(parentCategoryInfo == null)
  {
    parentCategoryInfo = new HashMap();
  }       
       
  String strParentCategoryName = "";
  String strCategoryCode = "";
  if(bIsEdit)
  {
    strParentCategoryName = (String)categoryInfo.get("parentcategoryname");  
    strCategoryCode = (String)categoryInfo.get("categorycode");  
    strCategoryId = String.valueOf(categoryInfo.get("categoryid"));
 }
  if(bIsNewChild)
  {
    strParentCategoryName = (String)parentCategoryInfo.get("categoryname");  
    strParentCategoryId = String.valueOf(parentCategoryInfo.get("categoryid"));
  }
  if(strParentCategoryName == null)
  {
    strParentCategoryName = new String("");
  }
  cat.debug("The categoryInfo is :" + categoryInfo);
  
 
  if(!bIsEdit)
  {
    pageContext.removeAttribute("categoryinfo");
    
  }
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="../../js/ScriptLib.js"></script>

<script language="JavaScript">
function checkCategoryInfo(form)
{
  if(isEmpty(form.categorycode.value))
  {
    alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_Code",false))%>');
    return false;
  }

  return true;
}
function page_done()
{
  if(!checkForm(document.categoryeditform))return;  
  if(!checkCategoryInfo(document.categoryeditform))
  {
    return;
  }

   MLCSTransform(categoryeditform);
   emptyToNull(categoryeditform);  
   categoryeditform.numrows.value = Number(<%= ConstantProp.multiLangNumber %>)*(0+1)
       
  document.categoryeditform.actionname.value = "done";
  isRunning = true;
  document.categoryeditform.submit();
}
function page_mulilang(name,label,num,need)
{
  
  if(popwindow!=null)
    popwindow.close();
  var strurl="../../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=categoryeditform&module=PCM&mlctype="+label+"&nativelanguage="+need+"&schema=ovcategorylang&entityid=<custom:write name="categoryinfo" property="categoryid"/>&entitytype="+name+"&contentid=categorylangid&colindex="+num;
  var strStatus= "height=250, width=250,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
  popwindow=window.open(strurl, "newwindow",strStatus);
}

function page_setCategory(id,name)
{
  document.categoryeditform.stdcategoryid.value = id;
  document.categoryeditform.stdcategoryname.value = name;
  var remote = window.open("","newwindow");
  if (remote != null)
    remote.close();
}
</script>
</head>

<body>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr>
    <td>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td colspan="2" class="summary_top"></td>
        </tr>
        <tr>
          <td colspan="2"><img src="../../images/<%= strLanguageCode %>/quote.gif" width="16" height="11">
            <%= label.getLabelName("L_NECat") + label.getLabelName("L_Colon") %></td>
        </tr>
      </table>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
       <form name="categoryeditform" method="post" action="../../Dispatcher" target="_parent">
       <input type="hidden" name="pagename" value="categoryedit">
       <input type="hidden" name="actionname">
       <%if(bIsEdit){%>
       <input type="hidden" name="categoryid" value="<%=JspHelper.filterNull( strCategoryId )%>">   
                
       <%}%>
       <%if(bIsNewChild){%>
       <%if(request.getParameter("parentcategoryid") != null && !request.getParameter("parentcategoryid").equals("null")){%>
       <input type="hidden" name="parentcategoryid" value="<%=JspHelper.filterNull( request.getParameter("parentcategoryid") )%>">   
       <%}%>
       <input type="hidden" name="grade" value="<%=JspHelper.filterNull( request.getParameter("grade") )%>">  
       <input type="hidden" name="isbottom" value="<%=JspHelper.filterNull( new String("Y") )%>"> 
                                                                                                     
       <%}%>  
       <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( nCurOrgId )%>">
       <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">               
       <input type="hidden" name="datelastupdated" value="<%=JspHelper.filterNull( new java.sql.Date(new java.util.Date().getTime()) )%>">                                     
       <input type="hidden" name="numrows" value="2"> 

      
        <tr> 
          <td class="need" width="150"> <%= label.getLabelName("L_Code") + label.getLabelName("L_Colon") %></td>
          <td> 
            <input type="text" name="categorycode" size="34" <%=JspHelper.filterNull( strReadOnly )%> value="<%=JspHelper.filterNull( strCategoryCode )%>">
          </td>
        </tr>
            
        <tr> 
          <td class="need"> <%= label.getLabelName("L_CatName") + label.getLabelName("L_Colon") %></td>
          <td> 
            <custom:text name="categoryinfo" property="categoryname" size="34" command="notnull" module="PCM" label="L_CatName" needMLC="true" isFirstMLC="true" multiLangType="catn" entityId="categoryid" contentId="categorylangid" colIndex="0"/>
            <a onclick="page_mulilang('catn','L_CatName',0,'need');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a> 
            
          </td>
        </tr>
        
        <tr> 
          <td class="td-text">  <%= label.getLabelName("L_CatDesc") + label.getLabelName("L_Colon") %></td>
          <td> 
            <custom:text name="categoryinfo" property="categorydesc" size="34"  module="PCM" label="L_CatDesc" needMLC="true"  multiLangType="catd" colIndex="0"/>
            <a onclick="page_mulilang('catd','L_CatDesc',0,'need');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a> 
            
          </td>
        </tr>
        
        
        
        <tr> 
          <td class="td-text" height="13"><%= label.getLabelName("L_ParentCat") + label.getLabelName("L_Colon") %></td>
          <td>&nbsp;<oval:write name="parentcategoryinfo" property="categoryname"/></td>
        </tr>
 		<!-- 
        <tr>
        <td class="td-text"><%= label.getLabelName("L_STDCategory") + label.getLabelName("L_Colon") %></td>
        <td><custom:text property="stdcategoryname" name="categoryinfo"/>
        <a href="#" onClick='window.open("CategorySelect.jsp?<%= OvalTools.randomURL() %>&orgid=1", "newwindow", "height=450, width=300,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no")'><img src="<%=contextPath%>/images/<%= strLanguageCode %>/tree.gif" border="0"></a>
                <custom:hidden property="stdcategoryid" name="categoryinfo"/>
        </td>
        </tr>
		 -->


      </form>
      </table>
    </td>
  </tr>
  <tr>
    <td class="summary_top"></td>
  </tr>
  <tr>
    <td class="td_center"><a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
  </tr>
</table>
</body>
</html>


